Skip to content

New pattern - lambda-strands-agent-bedrock-cdk#3093

Open
NithinChandranR-AWS wants to merge 3 commits into
aws-samples:mainfrom
NithinChandranR-AWS:NithinChandranR-AWS-feature-lambda-strands-agent-bedrock-cdk
Open

New pattern - lambda-strands-agent-bedrock-cdk#3093
NithinChandranR-AWS wants to merge 3 commits into
aws-samples:mainfrom
NithinChandranR-AWS:NithinChandranR-AWS-feature-lambda-strands-agent-bedrock-cdk

Conversation

@NithinChandranR-AWS

Copy link
Copy Markdown
Contributor

Description

Deploy a Strands Agents SDK agent on AWS Lambda using the official Lambda layer (no custom packaging), with Amazon Bedrock as the model provider and custom Python tool use.

Features

  • Official Strands Agents Lambda layer (arn:aws:lambda:{region}:856699698935:layer:strands-agents-py3_12-x86_64:1)
  • Custom @tool decorator for calculator tool
  • Function URL for testing
  • Python 3.12, X86_64

Checklist

  • My code follows the Serverless Land patterns guidelines
  • I have updated the README.md
  • I have added example-pattern.json
  • I have tested this pattern and it works
  • CDK synth passes

…bda with Bedrock

Deploy a Strands Agents SDK agent on AWS Lambda using the official
Lambda layer, with Amazon Bedrock as the model provider and custom
Python tool use. Zero patterns exist for Strands Agents in the repo.
@NithinChandranR-AWS

Copy link
Copy Markdown
Contributor Author

Hi @biswanathmukherjee 👋 This is the first Strands Agents pattern — AWS's new open-source agent framework (launched 2026). Shows Lambda + Strands Agent Layer + Bedrock tool use. Unique service integration with zero existing coverage. Deployed and tested.

@NithinChandranR-AWS

Copy link
Copy Markdown
Contributor Author

Hi @bfreiberg 👋 — friendly nudge on this pattern. It's been deployed and tested end-to-end on a live AWS account. Happy to address any feedback. Thank you!

@marcojahn marcojahn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @NithinChandranR-AWS, thanks for your contribution, please find a few comments/requests for changes attached. Please review

Comment thread lambda-strands-agent-bedrock-cdk/README.md Outdated
Comment thread lambda-strands-agent-bedrock-cdk/package.json
Comment thread lambda-strands-agent-bedrock-cdk/src/agent/index.py Outdated
@NithinChandranR-AWS

NithinChandranR-AWS commented Jun 14, 2026

Copy link
Copy Markdown
Contributor Author

All comments addressed and pushed. Thanks for the thorough review, @marcojahn , Appreciate your time and help.

@NithinChandranR-AWS

NithinChandranR-AWS commented Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

Hi @marcojahn — all 5 items from your review are fixed and pushed. Thanks again for the thorough feedback.

@marcojahn marcojahn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verification failed — the invoke step errors out

I deployed and tested the sample (samples account, eu-central-1) following the README. Step 1 (describe-stacks) works, but step 2 (lambda invoke) fails: StatusCode 200 with FunctionError: "Unhandled", and output.json contains a Bedrock AccessDeniedException — the expected 1188 answer is never returned.

AccessDeniedException when calling ConverseStream: ... is not authorized to perform:
bedrock:InvokeModelWithResponseStream on resource:
arn:aws:bedrock:eu-central-1:<account>:inference-profile/eu.anthropic.claude-sonnet-4-20250514-v1:0

Root cause — us. vs eu. mismatch:

  1. index.py never reads the MODEL_ID env var — Agent(system_prompt=..., tools=[calculate]) is called with no model id, so the Strands SDK uses its default, which resolves to the eu. inference profile in eu-central-1.
  2. The IAM policy in the stack only grants the us. inference-profile ARN. The runtime call hits eu., so the grant doesn't match → access denied.

Fix direction: make the handler read MODEL_ID and pass it to the agent, and make the model id + IAM inference-profile ARN region-aware (or document/enforce that the sample is us-*-only) so the granted profile always matches the one actually invoked.

Comment thread lambda-strands-agent-bedrock-cdk/README.md
…-portable IAM, add architecture diagram

- Handler now reads MODEL_ID env var and passes to Agent(model=...)
- MODEL_ID auto-derives region prefix (us/eu/apac) from deploy region
- IAM policy uses wildcard for cross-region inference profile routing
- Updated model from legacy sonnet-4-20250514 to current sonnet-4-6
- Added text architecture diagram per reviewer request
- Fixed bare service names and <code> tags
@NithinChandranR-AWS

Copy link
Copy Markdown
Contributor Author

Thank you for the thorough deploy test, Marco. You're right -- the handler wasn't reading MODEL_ID from the environment. Fixed: the agent now explicitly reads and passes it, and the CDK derives the correct regional prefix. Re-deployed and verified in us-east-1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants